package com.ih.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.ih.mapper.CustomerMapper;
import com.ih.pojo.Customer;
import com.ih.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper mapper;
    /**
     * 返回所有客户
     *
     * @return
     */
    @Override
    public List<Customer> listCustomer() {
        return mapper.selectList(null);
    }

    /**
     * 添加客户信息
     *
     * @param customer 表单采集的客户信息
     * @return 受影响行数，大于0添加成功，否则添加失败
     */
    @Override
    public int saveCustomer(Customer customer) {

        return mapper.insert(customer);
    }

    /**
     * 根据客户ID删除对应的客户信息
     *
     * @param cid 客户ID
     * @return 受影响行数，大于0删除成功，否则删除失败
     */
    @Override
    public int deleteCustomerById(Integer cid) {
        QueryWrapper<Customer> qw=new QueryWrapper<>();
        qw.eq("cid",cid);
        return mapper.delete(qw);
    }

    /**
     * 根据客户ID查询对应的客户信息
     *
     * @param cid 客户ID
     * @return 客户信息
     */
    @Override
    public Customer getCustomerById(Integer cid) {
        QueryWrapper<Customer> qw = new QueryWrapper<>();
        qw.eq("cid",cid);
        return mapper.selectOne(qw);
    }

    /**
     * 修改客户信息
     *
     * @param customer
     * @return
     */
    @Override
    public int updateCustomer(Customer customer) {
        QueryWrapper<Customer> qw=new QueryWrapper<>();
        qw.eq("cid",customer.getCid());
        return mapper.update(customer,qw);
    }


    @Override
    public PageInfo<Customer> listCust(Customer customer,Integer pageSize,Integer pageNum) {
        List<Customer> list = mapper.listCustomer(customer);
        return new PageInfo<>(list);
    }


}
